Tell Statements
Tell statements specify the default target, the object to which commands are sent if they do not include a direct parameter. For example, in the following
Tell statement, the Close command does not include a direct parameter.
tell front window close end tellAs a result, the Close command is sent to the front window, the default target specified in the Tell statement.When AppleScript encounters a partial reference (a reference that does not specify every container of an object), it uses the default target to complete it. For example, in the following Tell statement, the reference
word 3
does not specify all of the containers of the word object, so AppleScript completes it with the default target.
tell front document of application "Scriptable Text Editor" delete word 3 end tellThe result is that the Delete command is sent to the third word of the front document of the Scriptable Text Editor.A Tell statement also indicates which dictionary AppleScript should use to interpret words contained in the statement. For example, the previous Tell statement tells AppleScript to use the Scriptable Text Editor dictionary, which contains the definitions for the Delete command and the word object. If the
Tell statement had not specified the application, AppleScript would not have understood the Delete command.If you refer to another application within a Tell statement to an application, AppleScript uses the dictionaries of both applications to interpret the words
in the statement. For example, in response to the following Tell statement, AppleScript uses the Microsoft Excel dictionary for definitions of the Copy command and cell object, and the Scriptable Text Editor dictionary for the definition of the word object.
tell application "Microsoft Excel" copy word 5 of document "TestDocument" of application ¬ "Scriptable Text Editor" to Cell "R1C1" of Document ¬ "spreadsheet"end tellAppleScript defines two variables,it
andme
, that you can use in
Tell statements.The variable
it
is the default target. The value ofit
is a reference, as in
tell document "Introduction" of application ¬ "Scriptable Text Editor" get name of it end tellThe value of the variableit
isdocument "Introduction" of application "Scriptable Text Editor"
. The result of the Get command is the string"Introduction"
.The variable
me
refers to the current script, as in
property name : "Script"tell document "Introduction" of application ¬ "Scriptable Text Editor" get name of me end tell --result: "Script"The referencename of me
refers to the name property of the current script. The result of the Get command is the string"Script"
.AppleScript defines another word,
my
, that you can use instead of the phraseof me
. For example, the following script is equivalent to the previous example:
property name : "Script"tell document "Introduction" of application ¬ "Scriptable Text Editor" get my name end tell --result: "Script"If you refer to a property in a Tell statement without using eitherit
orme
, AppleScript assumes that you want the property of the default target of the Tell statement. For example, the result of the Get command in the following Tell statement is"Introduction"
.
property name : "Script"tell document "Introduction" of application ¬ "Scriptable Text Editor" get name end tell --result: "Introduction"If AppleScript cannot find the property in the dictionary of the default target of the Tell statement, then it assumes you want the property of the current script. For example, the result of the Get command in the following Tell statement is1000000
.
property x : 1000000 tell document "Introduction" of application ¬ "Scriptable Text Editor" get x end tell --result: 1000000In addition to distinguishing script properties from object properties,me
andmy
are used to distinguish user-defined commands (subroutines)
from application commands in Tell statements. For more information,
see Chapter 8, "Handlers."
- Note
- Within tests in Filter references, the direct object is the object being tested, so the variable
it
refers to the object currently being tested. See "Using the Filter Reference Form" on page 140 for information about the use ofit
in tests.![]()